package com.android.music.prolyric;

import android.app.Activity;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class setting_library  extends Activity implements OnClickListener
{
	TextView lcolorSong,lcolorSinger,lcolorCountSong,lcolorAlbum,lcolorTime,lcolorFolder,lcolorTab,lcolorArtist;
	ImageView lbgr;
	AmbilWarnaDialog dialog;
	SharedPreferences shareColor;
	SharedPreferences.Editor editor;
	Button btnOk,btnCancel;	 
	int colorArtist,colorSong,colorSinger,colorCountSong,colorAlbum,colorTime,colorFolder,colorTab,imgBgr;
	int defaultColor = 0xffffffff;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_library);
		
		lcolorArtist = (TextView)findViewById(R.id.lcolorArtist);
		lcolorSong = (TextView)findViewById(R.id.lcolorSong);
		lcolorSinger = (TextView)findViewById(R.id.lcolorSinger);
		lcolorCountSong = (TextView)findViewById(R.id.lcolorCountSong);
		lcolorAlbum = (TextView)findViewById(R.id.lcolorAlbum);
		lcolorTime = (TextView)findViewById(R.id.lcolorTime);
		lcolorFolder = (TextView)findViewById(R.id.lcolorFolder);
		lcolorTab = (TextView)findViewById(R.id.lcolorTab);
		lbgr = (ImageView)findViewById(R.id.limgPlayer);
		btnOk = (Button)findViewById(R.id.lbtnOk);
		btnCancel = (Button)findViewById(R.id.lbtnCancel);
		
		lcolorArtist.setOnClickListener(this);
		lcolorCountSong.setOnClickListener(this);
		lcolorAlbum.setOnClickListener(this);
		lcolorSinger.setOnClickListener(this);
		lcolorSong.setOnClickListener(this);
		lcolorTime.setOnClickListener(this);
		lcolorFolder.setOnClickListener(this);
		lcolorTab.setOnClickListener(this);
		lbgr.setOnClickListener(this);
		btnOk.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		
		SharedPreferences prefs = getSharedPreferences("libraryColor", MODE_PRIVATE);
		
		colorSong= (int) prefs.getInt("songcolor",defaultColor);
		colorSinger= (int) prefs.getInt("singercolor",defaultColor);		
		colorTime=(int) prefs.getInt("timecolor",defaultColor);		
		colorCountSong=(int) prefs.getInt("countsongcolor",defaultColor);
		colorAlbum= (int) prefs.getInt("albumcolor",defaultColor);		
		colorTab=(int) prefs.getInt("tabcolor",defaultColor);
		colorFolder=(int) prefs.getInt("foldercolor",defaultColor);
		imgBgr=(int) prefs.getInt("lbgr",R.drawable.girl);
		colorArtist=(int) prefs.getInt("artistcolor",defaultColor);
		
		lcolorCountSong.setBackgroundColor(colorCountSong);
		lcolorAlbum.setBackgroundColor(colorAlbum);
		lcolorSinger.setBackgroundColor(colorSinger);
		lcolorSong.setBackgroundColor(colorSong);
		lcolorTime.setBackgroundColor(colorTime);
		lcolorFolder.setBackgroundColor(colorFolder);
		lcolorTab.setBackgroundColor(colorTab);
		lcolorArtist.setBackgroundColor(colorArtist);		
		lbgr.setBackgroundResource(imgBgr);
		
		shareColor = getSharedPreferences("libraryColor", MODE_PRIVATE);
		editor = shareColor.edit();
		
		
		
		
	}
	public void onClick(View v) 
	{
		switch (v.getId()) 
		{
		case R.id.lcolorCountSong:
			dialog = new AmbilWarnaDialog(setting_library.this,colorCountSong, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorCountSong.setBackgroundColor(color);
					colorCountSong=color;
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
		case R.id.lcolorSong:
			dialog = new AmbilWarnaDialog(setting_library.this,colorSong, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorSong.setBackgroundColor(color);
					colorSong=color;					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
		
		case R.id.lcolorArtist:
			dialog = new AmbilWarnaDialog(setting_library.this,colorArtist, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorArtist.setBackgroundColor(color);
					colorArtist=color;					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.lcolorSinger:
			dialog = new AmbilWarnaDialog(setting_library.this,colorSinger, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorSinger.setBackgroundColor(color);
					colorSinger=color;					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.lcolorAlbum:
			dialog = new AmbilWarnaDialog(setting_library.this,colorAlbum, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorAlbum.setBackgroundColor(color);
					colorAlbum=color;
					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.lcolorTime:
			dialog = new AmbilWarnaDialog(setting_library.this, colorTime, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorTime.setBackgroundColor(color);
					colorTime=color;
					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.lcolorFolder:
			dialog = new AmbilWarnaDialog(setting_library.this, colorFolder, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorFolder.setBackgroundColor(color);
					colorFolder=color;
					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.lcolorTab:
			dialog = new AmbilWarnaDialog(setting_library.this, colorTab, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					lcolorTab.setBackgroundColor(color);
					colorTab=color;
					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.limgPlayer:
			startActivityForResult(new Intent(setting_library.this, setting_background.class),2000);	
			break;
		case R.id.lbtnOk:
			editor.putInt("countsongcolor",colorCountSong);
			editor.putInt("songcolor", colorSong);
			editor.putInt("singercolor", colorSinger);
			editor.putInt("tabcolor", colorTab);
			editor.putInt("timecolor", colorTime);
			editor.putInt("foldercolor", colorFolder);
			editor.putInt("albumcolor", colorAlbum);
			editor.putInt("lbgr",imgBgr);
			editor.putInt("artistcolor", colorArtist);
			
			editor.commit();
			Toast.makeText(setting_library.this, "Save data succeesful", Toast.LENGTH_LONG);
						
			break;
		case R.id.lbtnCancel:
			finish();
			break;

		default:
			break;
		}
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) 
	{
		if(requestCode==2000)
			if(resultCode==RESULT_OK)
			{
				imgBgr = Integer.parseInt(data.getData().toString());				
				lbgr.setBackgroundResource(imgBgr);
			}
	}
	
}
